import streamlit as st
import pandas as pd

def display_process_table(json_data: list):
    """
    将流程节点的 JSON 列表数据转化为标准表格，并在 Streamlit 页面中展示。

    参数:
        json_data (list): 包含流程步骤的 JSON 对象列表，每个对象可能包含以下字段：
                          id, now_state, next_state, condition, parameter
    """
    # 补全缺失字段
    for item in json_data:
        item.setdefault("now_state", "")
        item.setdefault("next_state", "")
        item.setdefault("condition", "")
        item.setdefault("parameter", "")

    # 创建 DataFrame
    df = pd.DataFrame(json_data, columns=["id", "now_state", "next_state", "condition", "parameter"])
    print(df)

# 示例数据
example_data = [
    {"id": 1, "now_state": "start", "next_state": "选择初审稿件"},
    {"id": 2, "now_state": "选择初审稿件", "next_state": "选择外审专家"},
    {"id": 3, "now_state": "选择初审稿件", "next_state": "汇总评审意见"},
    {"id": 4, "now_state": "选择外审专家", "next_state": "接收评审意见"},
    {"id": 5, "now_state": "汇总评审意见", "next_state": "发送外审邮件"},
    {"id": 6},
    {"id": 7, "now_state": "发送外审邮件", "next_state": "end"}
]

display_process_table(example_data)
